home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CTFASMTT.ZIP / LESSON4.DOC < prev    next >
Encoding:
Text File  |  1994-10-30  |  3.9 KB  |  85 lines

  1. LESSON4 - STACK (PUSH,POP) AND MORE COMMANDS
  2.  
  3. stack, how does it work well the law if last in first out,
  4. the principle is if I enter a series of numbers like : 1 34 54 54 65
  5. and then I take em out I will get : 65 54 54 34 1.
  6. in assembly the command is push (it can push only 16bit) and
  7. the reverse is pop.
  8.  
  9. so lets say I want to save the ds and later get it back :
  10.  
  11. push ds
  12. .
  13. .
  14. .
  15. .
  16. pop ds
  17.  
  18. mov ax,4c00h      ; short cut for : mov ah,4ch mov al,0
  19. int 21h
  20.  
  21. ok now you've got the basic of assembly (I hope).
  22.  
  23. in order to pass to the next level we have to explore the structure of the 8
  24. bit register !!! (I hope you you binary very good cause I wont explain)
  25. now bit is a condition that can be 0 or 1 so if we have 8 bit so the
  26. number of combinations can be 2^8 which is 256 (0..255) the limit
  27. of one byte (or word 2^16 65535) so assembly gives us the tools
  28. to modify and alter those bits.
  29.  
  30. SHR destination,count     : Shift arithmic right divide the number by
  31.                             count^2 so 1 is 2 and 2 is 4 and so on
  32.                             "shr ax,4" will divide ax by 16 (4^2)
  33. SHL destination,count     : Shift arithmic left multiply the number by
  34.                             count^2 so 1 is 2 and 2 is 4 and so on
  35.                             "shr ax,4" will multiply ax by 16 (4^2)
  36. ROR destination,count     : Rotate right rotates the bits right so
  37.                             bit 0 is now bit 7 (16 bit, bit 0 is bit 15)
  38.                             and does is by count.
  39.                             "ror al,8" will not affect cause there are
  40.                             only 8 bits so a whole round will be preformed.
  41. ROL destination,count     : Rotate left rotates the bits right so
  42.                             bit 7 is now bit 0 (16 bit, bit 15 is bit 0)
  43.                             and does is by count.
  44.                             "ror al,8" will not affect cause there are
  45.                             only 8 bits so a whole round will be preformed.
  46. DIV factor                : Divide will divide ax (or al) by the factor
  47.                             ("dx" must be set to 0), "div cl" will divide
  48.                             al by cl, "div cx" will divide ax by cx.
  49. MUL factor                : Multiply will multiply ax (or al) by the factor
  50.                             (dx will be altered), if the operation is 8 bit
  51.                             "div cl" then the sum will be stored in ax
  52.                             (if it passes 8 bit) "mul cl" will mul ax by cl,
  53.                             "mul cx" will multiply ax by cx.
  54. NEG destination           : Negation what it does he reverses negativity
  55.                             lets say we have 4 so it will become -4 and
  56.                             vise verse (n*-1)
  57.  
  58. as you might have noticed no floating points nor integers has been discussed 
  59. well assembly has non !!!! floating points (don't be shocked) because you can
  60. still use the precision well how do you ask, there are fixed points.
  61. fixed points are precision that was shifted before and after the calc
  62. been shifted back. fixed points example :
  63.  
  64. mov ax,100       ; our circle radios
  65. mov cx,181       ; 181/256 is 0.707 (sin(45))
  66. mul cx           ; multiply (result : 18,100)
  67.  
  68. shr ax,8         ; now the number is shifted back (n / 256 = shr n,8 cause
  69.                  ; 2^8 is 256) so the result is 70.7 (the point disapears)
  70.                  ; number is trunced to 70 (if you check 100*0.707 is 70.7)
  71.  
  72. the fixed points are much faster then real (double) and usually the
  73. sin cos table is being written onto a file predifined by pascal,c
  74. example for extracting cos(56) to fix :
  75.  
  76. var
  77.   a:integer ;
  78. begin
  79.   a:=trunc(cos(56*pi/180)*256) ;
  80. end ;
  81.  
  82. now first we converted deg to rad and then multiply it by our factor.
  83. but, but, but noticed shr,shl,ror,rol do not work on integers,
  84. it will get wacked and will bug you program, so we need to detect
  85. if it's lower/higher then zero so we go to next chapter (flags and jumps)